home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue24 / ntserv / WinSvcX.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1997-07-04  |  6.3 KB  |  191 lines

  1. unit WinSvcX;
  2.  
  3. interface
  4.  
  5. {===============================================================================}
  6. { This unit is simply for use with the NT Service demonstration supplied with   }
  7. { the Delphi magazine.                                                          }
  8. { It contains only those definitions required to support the article. The source}
  9. { for the defintions are Winnt.H and WinSVC.Pas (from the Delphi3 version).     }
  10. {===============================================================================}
  11.  
  12. uses Windows;
  13.  
  14.   { >>>>>>>> Start of definitions originating in WinNT.H }
  15.  
  16. const
  17.  
  18.   { Event types}
  19.  
  20.   EVENTLOG_SUCCESS          = $0000;
  21.   EVENTLOG_ERROR_TYPE       = $0001;
  22.   EVENTLOG_WARNING_TYPE     = $0002;
  23.   EVENTLOG_INFORMATION_TYPE = $0004;
  24.   EVENTLOG_AUDIT_SUCCESS    = $0008;
  25.   EVENTLOG_AUDIT_FAILURE    = $0010;
  26.  
  27.   { Service types }
  28.  
  29.   SERVICE_WIN32_OWN_PROCESS   = $00000010;
  30.   SERVICE_WIN32_SHARE_PROCESS = $00000020;
  31.   SERVICE_INTERACTIVE_PROCESS = $00000100;
  32.  
  33.   { Service start types }
  34.  
  35.   SERVICE_BOOT_START        = $00000000;
  36.   SERVICE_SYSTEM_START      = $00000001;
  37.   SERVICE_AUTO_START        = $00000002;
  38.   SERVICE_DEMAND_START      = $00000003;
  39.   SERVICE_DISABLED          = $00000004;
  40.  
  41.   { Service start error options }
  42.  
  43.   SERVICE_ERROR_IGNORE      = $00000000;
  44.   SERVICE_ERROR_NORMAL      = $00000001;
  45.   SERVICE_ERROR_SEVERE      = $00000002;
  46.   SERVICE_ERROR_CRITICAL    = $00000003;
  47.  
  48.   SECURITY_DESCRIPTOR_REVISION = 1;
  49.  
  50.   { >>>>>>>> End of definitions originating in WinNT.H }
  51.  
  52.   { The following come from WinSVC.Pas }
  53.  
  54. // Service control requests }
  55.  
  56.   SERVICE_CONTROL_STOP        = $00000001;
  57.   SERVICE_CONTROL_PAUSE       = $00000002;
  58.   SERVICE_CONTROL_CONTINUE    = $00000003;
  59.   SERVICE_CONTROL_INTERROGATE = $00000004;
  60.   SERVICE_CONTROL_SHUTDOWN    = $00000005;
  61.  
  62. // Service State -- for CurrentState
  63.  
  64.   SERVICE_STOPPED          = $00000001;
  65.   SERVICE_START_PENDING    = $00000002;
  66.   SERVICE_STOP_PENDING     = $00000003;
  67.   SERVICE_RUNNING          = $00000004;
  68.   SERVICE_CONTINUE_PENDING = $00000005;
  69.   SERVICE_PAUSE_PENDING    = $00000006;
  70.   SERVICE_PAUSED           = $00000007;
  71.  
  72. // Controls Accepted  (Bit Mask)
  73.  
  74.   SERVICE_ACCEPT_STOP           = $00000001;
  75.   SERVICE_ACCEPT_PAUSE_CONTINUE = $00000002;
  76.   SERVICE_ACCEPT_SHUTDOWN       = $00000004;
  77.  
  78. // Handle Types
  79.  
  80. type
  81.   SC_HANDLE = THandle;
  82.   SERVICE_STATUS_HANDLE = DWORD;
  83.  
  84. // Service Status Structure
  85.  
  86. type
  87.   PServiceStatus = ^TServiceStatus;
  88.   TServiceStatus = record
  89.     dwServiceType: DWORD;
  90.     dwCurrentState: DWORD;
  91.     dwControlsAccepted: DWORD;
  92.     dwWin32ExitCode: DWORD;
  93.     dwServiceSpecificExitCode: DWORD;
  94.     dwCheckPoint: DWORD;
  95.     dwWaitHint: DWORD;
  96.   end;
  97.  
  98. // Prototype for the Service Main Function
  99.  
  100. type
  101.   TServiceMainFunction = TFarProc;
  102.  
  103. // Prototype for the Service Control Handler Function
  104.  
  105. type
  106.   THandlerFunction = TFarProc;
  107.  
  108. //
  109. // Service Start Table
  110. //
  111. type
  112.   PServiceTableEntry = ^TServiceTableEntry;
  113.   TServiceTableEntry = record
  114.     lpServiceName: PAnsiChar;
  115.     lpServiceProc: TServiceMainFunction;
  116.   end;
  117.  
  118. // Service Control Manager object specific access types
  119.  
  120. const
  121.   SC_MANAGER_CONNECT            = $0001;
  122.   SC_MANAGER_CREATE_SERVICE     = $0002;
  123.   SC_MANAGER_ENUMERATE_SERVICE  = $0004;
  124.   SC_MANAGER_LOCK               = $0008;
  125.   SC_MANAGER_QUERY_LOCK_STATUS  = $0010;
  126.   SC_MANAGER_MODIFY_BOOT_CONFIG = $0020;
  127.  
  128.   SC_MANAGER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED or
  129.                            SC_MANAGER_CONNECT or
  130.                            SC_MANAGER_CREATE_SERVICE or
  131.                            SC_MANAGER_ENUMERATE_SERVICE or
  132.                            SC_MANAGER_LOCK or
  133.                            SC_MANAGER_QUERY_LOCK_STATUS or
  134.                            SC_MANAGER_MODIFY_BOOT_CONFIG);
  135.  
  136. // Service object specific access type
  137.  
  138.   SERVICE_QUERY_CONFIG         = $0001;
  139.   SERVICE_CHANGE_CONFIG        = $0002;
  140.   SERVICE_QUERY_STATUS         = $0004;
  141.   SERVICE_ENUMERATE_DEPENDENTS = $0008;
  142.   SERVICE_START                = $0010;
  143.   SERVICE_STOP                 = $0020;
  144.   SERVICE_PAUSE_CONTINUE       = $0040;
  145.   SERVICE_INTERROGATE          = $0080;
  146.   SERVICE_USER_DEFINED_CONTROL = $0100;
  147.  
  148.   SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED or
  149.                         SERVICE_QUERY_CONFIG or
  150.                         SERVICE_CHANGE_CONFIG or
  151.                         SERVICE_QUERY_STATUS or
  152.                         SERVICE_ENUMERATE_DEPENDENTS or
  153.                         SERVICE_START or
  154.                         SERVICE_STOP or
  155.                         SERVICE_PAUSE_CONTINUE or
  156.                         SERVICE_INTERROGATE or
  157.                         SERVICE_USER_DEFINED_CONTROL);
  158.  
  159. function CloseServiceHandle(hSCObject: SC_HANDLE): BOOL; stdcall;
  160. function CreateService(hSCManager: SC_HANDLE; lpServiceName, lpDisplayName: PChar;
  161.   dwDesiredAccess, dwServiceType, dwStartType, dwErrorControl: DWORD;
  162.   lpBinaryPathName, lpLoadOrderGroup: PChar; lpdwTagId: LPDWORD; lpDependencies,
  163.   lpServiceStartName, lpPassword: PChar): SC_HANDLE; stdcall;
  164. function DeleteService(hService: SC_HANDLE): BOOL; stdcall;
  165. function OpenSCManager(lpMachineName, lpDatabaseName: PChar;
  166.   dwDesiredAccess: DWORD): SC_HANDLE; stdcall;
  167. function OpenService(hSCManager: SC_HANDLE; lpServiceName: PChar;
  168.   dwDesiredAccess: DWORD): SC_HANDLE; stdcall;
  169. function RegisterServiceCtrlHandler(lpServiceName: PChar;
  170.   lpHandlerProc: ThandlerFunction): SERVICE_STATUS_HANDLE; stdcall;
  171. function SetServiceStatus(hServiceStatus: SERVICE_STATUS_HANDLE;
  172.   var lpServiceStatus: TServiceStatus): BOOL; stdcall;
  173. function StartServiceCtrlDispatcher(
  174.   var lpServiceStartTable: TServiceTableEntry): BOOL; stdcall;
  175.  
  176. implementation
  177.  
  178. const
  179.   ADVAPI32 = 'ADVAPI32.dll';
  180.  
  181. function CloseServiceHandle; external ADVAPI32 name 'CloseServiceHandle';
  182. function CreateService; external ADVAPI32 name 'CreateServiceA';
  183. function DeleteService; external ADVAPI32 name 'DeleteService';
  184. function OpenSCManager; external ADVAPI32 name 'OpenSCManagerA';
  185. function OpenService; external ADVAPI32 name 'OpenServiceA';
  186. function RegisterServiceCtrlHandler;external ADVAPI32 name 'RegisterServiceCtrlHandlerA';
  187. function SetServiceStatus; external ADVAPI32 name 'SetServiceStatus';
  188. function StartServiceCtrlDispatcher; external ADVAPI32 name 'StartServiceCtrlDispatcherA';
  189.  
  190. end.
  191.